const express = require('express');
const router = express.Router();
const adminController = require('../controllers/admin.controller');
const authMiddleware = require('../middlewares/auth.middleware');
const permissionMiddleware = require('../middlewares/permission.middleware');

// 管理员登录
router.post('/login', adminController.login);

// 创建超级管理员（特殊接口，不需要权限验证）
router.post('/createSuperAdmin', adminController.createSuperAdmin);

// 获取管理员信息
router.get('/profile', authMiddleware, adminController.getProfile);

// 更新管理员信息
router.put('/profile', authMiddleware, adminController.updateProfile);

// 修改密码
router.put('/password', authMiddleware, adminController.changePassword);

// 生成测试路由
router.get('/test', (req, res) => {
    res.send('Hello, World!');
})

// 管理员管理
router.post('/', authMiddleware, permissionMiddleware('admin:create'), adminController.createAdmin);
router.get('/', authMiddleware, permissionMiddleware('admin:read'), adminController.getAdminList);
router.get('/:id', authMiddleware, permissionMiddleware('admin:read'), adminController.getAdminById);
router.put('/:id', authMiddleware, permissionMiddleware('admin:update'), adminController.updateAdmin);
router.delete('/:id', authMiddleware, permissionMiddleware('admin:delete'), adminController.deleteAdmin);

module.exports = router;